package com.zkx.fssb.controller.server;


import com.zkx.fssb.domain.dto.CartDto;
import com.zkx.fssb.domain.po.Cart;
import com.zkx.fssb.result.Result;
import com.zkx.fssb.service.CartService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@Slf4j
@RestController("serverCartController")
@RequestMapping("/server/cart")
public class CartController {

    @Autowired
    private CartService cartService;

    @GetMapping
    public Result<List<Cart>> getCartListByUserId(Integer userId){
        List<Cart> cartList = cartService.getCartListByUserId(userId);

        return Result.success(cartList);
    }

    @PostMapping
    public Result saveCart(@RequestBody CartDto cartDto){

        cartService.saveCustomCart(cartDto);

        return Result.success("添加购物车成功");

    }


    @DeleteMapping
    public Result  deleteCart(CartDto cartDto){

        cartService.deleteCartByUserId(cartDto);

        return Result.success("删除购物车成功");

    }


}
